import React from 'react'
import { useSelector } from 'react-redux'
import { PostAuthor } from './PostAuthor'

export const SinglePostPage = ({ match }) => {
    const { postId } = match.params;
    const post = useSelector(state => state.posts.find(item => item.id == postId))

    if (!post) {
        return (<section><h2>页面未找到！</h2></section>)
    }

    return (<section>
        <article className="post">
            <h2>{post.title}</h2>
            <p className="post-content">{post.content}</p>
            <PostAuthor userId={post.userId}></PostAuthor>
        </article>
    </section>)
}